<?php
/*
 *  @author Nicolas Genevaux
 * (c)nige 2008
 */
	include_once($RACINE.'inc/var.pages.php');
	include_once($RACINE.'inc/fct.utils.php');
	include_once($RACINE.'inc/sql.exercicerealise.php');
	include_once($RACINE.'inc/sql.inscrit.php');
	$IDMATIERE = $_SESSION['IDMATIEREDETAIL'];
	include($RACINE.'inc/var.points.php');
	if(isset($_SESSION['ID_TEST'])&&($_POST['accept']==1)) {
		$idcon = $_SESSION['ID_CONECT'];
		$idtes = $_SESSION['ID_TEST'];
		$idmat = $_SESSION['IDMATIEREDETAIL'];
		$matlvl = $_SESSION['MATIEREDETAILLEVEL'];
		$_SESSION = array();
		$_SESSION['ID_CONECT'] = $idcon;
		$_SESSION['ID_TEST'] = $idtes;
		$_SESSION['IDMATIEREDETAIL'] = $idmat;
		$_SESSION['MATIEREDETAILLEVEL'] = $matlvl;
		redirect($PAGE_TEST_LIBRE);
	}
	else if($_POST['accept']==2) {
			redirect($PAGE_ACCUEIL);
	}
	else {
		if(isset($_SESSION['ID_CONECT'])) {
			$_SESSION['ID_TEST'] = $_SESSION['ID_CONECT'];
		}
		else {
			$res = doSQL($INSCRIT_SELECT_IP,array(0=>"'".$_SERVER['REMOTE_ADDR']."'"));
			$_SESSION['ID_TEST'] = $res['identifiant'];
		}
		if(!isset($_SESSION['ID_TEST'])) {
			doSQL($INSCRIT_RECORD,array(0=>"''",1=>"''",2=>"'".$_SERVER['REMOTE_ADDR']."'",3=>"''",4=>"''"));
			$_SESSION['ID_TEST'] = getLastInsertID();
		}
		$exercices = doSQL($EXERCICEREALISE_TODAY,array(0=>$_SESSION['ID_TEST']));
		if(!isset($INSCRIT->points)) {
			if($exercices['total']>0) {
				$_SESSION['ID_TEST'] = '';
				include($RACINE.'texte/test_novalideunknown.php');
			}
			else {
				include($RACINE.'texte/test_validerunknown.php');
			}
		}
		else {
			if($INSCRIT->points < $TESTS) {
				$_SESSION['ID_TEST'] = '';
				include($RACINE.'texte/test_novalideidentif.php');
			}
			else {
				if($_SESSION['IDMATIEREDETAIL']>0) {
					$_SESSION['MATIEREDETAILLEVEL'] = $_POST['level'];
					include($RACINE.'texte/test_valideridentifdetail.php');
				}
				else {
					include($RACINE.'texte/test_valideridentif.php');
				}
			}
		}
	}
?>
